import qs from "qs";
import http from "@/api";
import { laboratoryListType } from "./type";

// 使用枚举包含有所有Path
enum Api {
  // 查询实验室
  selectLaboratory = "/tbLab/select",
  // 添加实验室
  addLaboratory = "/tbLab/add",
  // 修改实验室
  editLaboratory = "/tbLab/edit",
  // 删除实验室
  delLaboratory = "/tbLab/delete"
}

// 查询实验室的Api
export const selectLaboratoryApi = () => {
  return http.post<laboratoryListType>(Api.selectLaboratory, {}, { loading: false });
};

// 添加实验室的Api
export const addLaboratoryApi = (data: { name: string; address: string; pid: string | number | null }) => {
  let dataQ = "?" + qs.stringify(data);
  console.log("添加实验室提交数据", data);
  return http.post(Api.addLaboratory + dataQ, {}, { loading: false });
};

// 编辑实验室的Api
export const editLaboratoryApi = (data: { id: string | number | null; name: string; address: string }) => {
  let dataQ = "?" + qs.stringify(data);
  console.log("添加实验室提交数据", data);

  return http.post(Api.editLaboratory + dataQ, {}, { loading: false });
};

// 删除实验室的Api
export const delLaboratoryApi = (data: { tbLabId: number | string | null | undefined }) => {
  let dataQ = "?" + qs.stringify(data);
  return http.post(Api.delLaboratory + dataQ, {}, { loading: false });
};
